﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MSAcademic.v2.Web.Models;
using StructureMap;
using MSAcademic.v2.Infrastructure.Search;

namespace MSAcademic.v2.Web.Controllers
{
    public partial class SearchController : Controller
    {
        public ActionResult Search()
        {
            var vModel = _viewSearchModel();
            vModel.IsPost = false;

            return View(vModel);
        }
        [HttpPost]
        public ActionResult Search(string title)
        {
            var vModel = _viewSearchModel();
            vModel.Title = title;
            vModel.IsPost = true;

            return View(vModel);
        }

        public ActionResult SearchViaUri(string title)
        {
            var vModel = _viewSearchModel();
            vModel.Title = HttpUtility.UrlDecode(title);
            vModel.IsPost = true;

            return View("Search", vModel);
        }

    }

    public partial class SearchController
    {
        private readonly Func<SearchModel> _viewSearchModel;

        public SearchController(
            Func<SearchModel> viewSearchModel)
        {
            _viewSearchModel = viewSearchModel;
        }
    }
}
